<?php

namespace App\Http\Lib;


class Output
{
    public static function successPage($text, $redirect = '/')
    {
        return view('succeed', [
            'text' => $text,
            'redirect' => $redirect,
            'app_url' => env('APP_URL')
        ]);
    }

    public static function errorPage($errcode = 10000, $errmessage = 'Error')
    {
        if ( is_string($errcode) && $errmessage == 'Error' ) {
            $errmessage = $errcode;
            $errcode    = 10000;
        } else if ( $errmessage == 'Error' ) {
            $errmessage = ErrorCode::getMessage($errcode);
        }
        return view('error', [
            'errmessage' => $errmessage,
            'errcode' => $errcode,
            'app_url' => env('APP_URL')
        ]);
    }

    public static function e($errcode = 10000, $errmessage = 'Error', $assist = false)
    {
        if ( is_string($errcode) && $errmessage == 'Error' ) {
            $errmessage = $errcode;
            $errcode    = 10000;
        } else if ($errmessage == 'Error'){
            $errmessage = ErrorCode::getMessage($errcode);
        }
        if ( $assist ) {
            return compact("errcode", "errmessage", "assist");
        } else {
            return compact("errcode", "errmessage");
        }
    }

    public static function o($data, $code = 0, $trigger = 'none')
    {
        return [
            'errcode'    => $code,
            'errmessage' => 'ok',
            'trigger'    => $trigger,
            'data'       => $data,
        ];
    }

}